home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / X / XtAppInitwIcon / Initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.4 KB  |  135 lines

  1. /*------------------------------------------------------------------------
  2.  *                                                                        *
  3.  *      Copyright (C) 1991, 1992, 1993, 1994, Silicon Graphics, Inc.      *
  4.  *                          All Rights Reserved.                          *
  5.  *                                                                        *
  6.  *  The files in this subtree  contain  UNPUBLISHED  PROPRIETARY  SOURCE  *
  7.  *  CODE of Silicon Graphics, Inc.;  the  contents  of  these  files may  *
  8.  *  not be disclosed to third  parties,  copied  or  duplicated  in  any  *
  9.  *  form, in whole or in part,  without  the  prior  written  permission  * 
  10.  *  of  Silicon Graphics, Inc.                                            *
  11.  *                                                                        *
  12.  *  RESTRICTED RIGHTS LEGEND:                                             *
  13.  *  Use,  duplication  or  disclosure  by  the  Government is subject to  *
  14.  *  restrictions as set forth in subdivision (c)(1)(ii) of the Rights in  *
  15.  *  Technical Data and Computer Software clause at  DFARS  252.227-7013,  *
  16.  *  and/or in similar or successor  clauses in the FAR,  DOD or NASA FAR  *
  17.  *  Supplement.  Unpublished - rights reserved  under the Copyright Laws  *
  18.  *  of the United States.                                                 *
  19.  *                                                                        *
  20.  *  THIS SOFTWARE IS  PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,  *
  21.  *  EXPRESS,  IMPLIED OR  OTHERWISE,  INCLUDING  WITHOUT LIMITATION, ANY  *
  22.  *  WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.      *
  23.  *                                                                        *
  24.  *  IN  NO  EVENT  SHALL  SILICON  GRAPHICS  BE  LIABLE FOR ANY SPECIAL,  *
  25.  *  INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF  ANY  KIND,  OR ANY  *
  26.  *  DAMAGES WHATSOEVER RESULTING FROM LOSS  OF  USE,  DATA  OR  PROFITS,  *
  27.  *  WHETHER OR NOT ADVISED OF  THE  POSSIBILITY  OF  DAMAGE,  AND ON ANY  *
  28.  *  THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  *
  29.  *  PERFORMANCE OF THIS SOFTWARE.                                         *
  30.  **************************************************************************
  31.  *
  32.  * This file contains a new version of XtAppInitialize.  It performs all
  33.  * the same functions except allows the user to create their own icon
  34.  * window at the appropriate time.
  35.  *------------------------------------------------------------------------*/
  36.  
  37. #include <stdio.h>
  38.  
  39. #include "Initialize.h"
  40.  
  41. #include <X11/StringDefs.h>
  42. #include <X11/Shell.h>
  43.  
  44. /*------------------------------------------------------------------------
  45.  *    Function Name:    XtAppInitializeWithIcon
  46.  *    Description:    Identical to XtAppInitialize except allows the
  47.  *            application to generate an icon window at the
  48.  *            appropriate time.
  49.  *    Arguments:    app_context_return    The application context
  50.  *                        of the application.
  51.  *            app_class        The class of the application
  52.  *            options            The option list.
  53.  *            num_options        The number of options.
  54.  *            argc_in_out        'argc' from main routine
  55.  *            argv_in_out        'argv' from main routine
  56.  *            fallback_resources    List of fallback resources
  57.  *            args, num_args        Arguments to use when
  58.  *                        creating the shell widget.
  59.  *            makeIcon        Pointer to the function
  60.  *                        to call when the icon is
  61.  *                        to be made.
  62.  *    Returns:    The shell widget.
  63.  *------------------------------------------------------------------------*/
  64.  
  65. Widget XtAppInitializeWithIcon (XtAppContext*        app_context_return,
  66.                 String            app_class,
  67.                 XrmOptionDescRec*    options,
  68.                 Cardinal        num_options,
  69. #if XtSpecificationRelease > 4
  70.                 int*            argc_in_out,
  71. #else
  72.                 Cardinal*        argc_in_out,
  73. #endif
  74.                 String*            argv_in_out,
  75.                 String*            fallback_resources,
  76.                 ArgList            args_in,
  77.                 Cardinal        num_args,
  78.                 makeIcon        doIcon)
  79. {
  80.     XtAppContext    app_con;
  81.     Display*        dpy;
  82.     String*        saved_argv;
  83.     int            i, saved_argc = *argc_in_out;
  84.     Widget        root;
  85.     Arg            args[4], *merged_args;
  86.     Cardinal        num = 0;
  87.     Window        icon;
  88.  
  89.     XtToolkitInitialize ();
  90.  
  91.     /*----
  92.      * Save away argv so we can set the properties later.
  93.      *----*/
  94.  
  95.     saved_argv = (String *) XtMalloc ((*argc_in_out + 1) * sizeof (String));
  96.     for (i = 0; i < saved_argc; i++)
  97.     saved_argv[i] = argv_in_out[i];
  98.     saved_argv[i] = NULL;
  99.  
  100.     app_con = XtCreateApplicationContext ();
  101.  
  102.     if (fallback_resources != NULL)
  103.     XtAppSetFallbackResources (app_con, fallback_resources);
  104.  
  105.     dpy = XtOpenDisplay (app_con, (String)NULL, (String)NULL, app_class,
  106.              options, num_options, argc_in_out, argv_in_out);
  107.  
  108.     if (dpy == NULL)
  109.     XtErrorMsg ("invalidDisplay", "xtInitializeWithIcon",
  110.             "XtInitializeWithIcon", "Can't open display",
  111.             (String *)NULL, (Cardinal *)NULL);
  112.  
  113.     if (doIcon)
  114.     icon = (*doIcon) (dpy, argc_in_out, argv_in_out);
  115.  
  116.     if (icon)
  117.     XtSetArg (args[num], "iconWindow", icon); num++;
  118.     XtSetArg (args[num], XtNscreen, DefaultScreenOfDisplay (dpy)); num++;
  119.     XtSetArg (args[num], XtNargc, saved_argc); num++;
  120.     XtSetArg (args[num], XtNargv, saved_argv); num++;
  121.     merged_args = XtMergeArgLists (args_in, num_args, args, num);
  122.     num += num_args;
  123.  
  124.     root = XtAppCreateShell (NULL, app_class, applicationShellWidgetClass,
  125.                  dpy, merged_args, num);
  126.  
  127.     if (app_context_return != NULL)
  128.     *app_context_return = app_con;
  129.  
  130.     XtFree ((XtPointer)merged_args);
  131.     XtFree ((XtPointer)saved_argv);
  132.  
  133.     return root;
  134. }
  135.